<template>
  <div id="info_container">
    <div class="info_container_main">
      <p>管理员信息</p>

      <div>管理员ID:{{ userid }}</div>
      <div>账号:{{ username }}</div>
      <div>用户组:{{ usergroup }}</div>
      <div>创建时间:{{ usertime }}</div>

      <div class="imgbox">
        上传头像:
        <el-upload
          :data="imgid"
          class="avatar-uploader"
          action="http://127.0.0.1:5000/users/avatar_upload"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
        >
          <img v-if="imageUrl" :src="imageUrl" class="avatar" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </div>
    </div>
  </div>
</template>

<script>
import { account } from "@/apis/users";
import { getYYYYMMDD } from "@/utils/utils";
import { bus } from "@/utils/utils";
export default {
  data() {
    return {
      userid: "",
      username: "",
      usergroup: "",
      usertime: "",

      imageUrl: "",

      //上传头像附带参数
      imgid: { id: localStorage.id },
    };
  },
  methods: {
    handleAvatarSuccess(res, file) {
      console.log(res, file);
      this.imageUrl = URL.createObjectURL(file.raw);
      // location.reload();
      bus.$emit("photo", this.imageUrl);
    },
  },
  created() {
    account({ id: localStorage.id }).then((res) => {
      console.log(res);
      this.userid = res.data.accountInfo.id;
      this.username = res.data.accountInfo.account;
      this.usergroup = res.data.accountInfo.userGroup;

      //转换时间格式
      res.data.accountInfo.ctime = getYYYYMMDD(res.data.accountInfo.ctime);
      this.usertime = res.data.accountInfo.ctime;
    });
  },
};
</script>

<style lang="less" scoped>
#info_container {
  height: 100%;
  background-color: #f0f2f5;
  .info_container_main {
    padding: 0 20px 40px 20px;
    background-color: #fff;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    p {
      line-height: 50px;
      border-bottom: 1px solid #f4f5f9;
      color: #848485;
      margin-bottom: 20px;
    }
    div {
      line-height: 40px;
      color: #636465;
      border-bottom: 1px solid #f4f5f9;
    }
    .imgbox {
      width: 300px;
      display: flex;
      align-items: center;
      margin-top: 20px;
      .avatar-uploader,
      .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
        width: 178px;
        height: 178px;
      }
      .avatar-uploader:hover {
        border-color: #409eff;
      }
      .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        line-height: 178px;
        text-align: center;
      }
      .avatar {
        width: 178px;
        height: 178px;
        display: block;
      }
    }
  }
}
</style>